package com.gopay.common.riskcontrol.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.riskcontrol.RcComLimitConf;
import com.gopay.common.riskcontrol.dao.RcComLimitConfQueryDAO;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * Created by zhaojt on 2017/5/23.
 */
@Repository("rcComLimitConfQueryDAO")
public class RcComLimitConfQueryDAOImpl extends BaseDAOImpl<RcComLimitConf, Serializable> implements RcComLimitConfQueryDAO {

    @Override
    public List<RcComLimitConf> queryLimitCfg(String intTxnCd, String payChannel, String acctProd,String custType, String creditRanks) {
        DetachedCriteria criteria = DetachedCriteria.forClass(RcComLimitConf.class);
        criteria.add(Restrictions.eq("intTxnCd", intTxnCd));
        criteria.add(Restrictions.eq("acctProd", acctProd));
        criteria.add(Restrictions.eq("custType",custType));
        criteria.add(Restrictions.eq("isEnabled", "01"));
        criteria.add(Restrictions.in("creditRanks", new String[]{creditRanks, "ALL"}));
        if(StringUtils.isNotBlank(payChannel)){
            criteria.add(Restrictions.in("payChannel", new String[]{payChannel, "ALL"}));
        }else {
            criteria.add(Restrictions.eq("payChannel", "ALL"));
        }
        List<RcComLimitConf> list = this.findByCriteria(criteria);
        return list;
    }

}
